#include <iostream>

using namespace std;

class AbstractFruit
{
public:
	virtual void fruitName() = 0;
};

class Apple : public AbstractFruit
{
public:
	virtual void fruitName()
	{
		cout << "apple" << endl;
	}
};

class Banana : public AbstractFruit
{
public:
	virtual void fruitName()
	{
		cout << "Banana" << endl;
	}
};


class FruitFactory
{
public:
	AbstractFruit *creatFruit(string name)
	{
		if (name == "apple")
		{
			return new Apple;
		}
		else if (name == "banana")
		{
			return new Banana;
		}
		else
		{
			return nullptr;
		}
	}
};

void functionTest()
{
	FruitFactory *factory = new FruitFactory;
	AbstractFruit *fruit = factory->creatFruit("apple");
	fruit->fruitName();

	delete fruit;

	fruit = factory->creatFruit("banana");
	fruit->fruitName();

	delete fruit;
}

int main()
{
	functionTest();

	system("pause");
	return 0;
}


//#include <iostream>
//#include <string>
//
//using namespace std;
//
//void functionTest()
//{
//
//}
//
//int main()
//{
//	functionTest();
//
//	system("pause");
//	return 0;
//}